
<%@ page import="com.macrosolution.exdebito.Pratica" %>
<%@ page import="com.macrosolution.exdebito.Interview" %>
<%@ page import="com.macrosolution.exdebito.AnomaliaBancaria" %>
<%@ page import="com.macrosolution.exdebito.Sovraindebitamento" %>

<!DOCTYPE html>
<html>

	<head>
		<meta name="layout" content="kickstart"/>
		<title>Mr-Rights|Lista Interviste</title>
	</head>
<body>
<!-- RIBBON Macro Categori-->
<div id="ribbon">
	<ol class="breadcrumb">
		<li>Pratiche</li><li>lista</li>
	</ol>
</div>
<!-- END RIBBON -->


<!-- MAIN CONTENT -->
<div id="content">
<div class="row">
	<div class="col-lg-12">
		<div class="jarviswidget jarviswidget-color-darken" id="wid-id-0" data-widget-editbutton="false">
			<div>
				<!-- widget edit box -->
				<div class="jarviswidget-editbox">
					<!-- This area used as dropdown edit box -->

				</div>
				<!-- end widget edit box -->
				
				<!-- widget content -->
				<div class="widget-body no-padding">
					<table id="dt_basic" class="table table-striped table-bordered table-hover" >
						<thead>			                
							<tr>
								<th >Cliente</th>
								<th >Creato</th>
								<th >Operatore</th>
								<th >Interv.</th>
								<th >Anom./Sovr.</th>
			<sec:ifAnyGranted roles="ROLE_ADMIN,ROLE_AMM,ROLE_BCKOFF">	
								<th >Avv.</th>
								<th >Perito/OCC</th>
			</sec:ifAnyGranted>							
								<th >Pratica</th>
								<th>Stato&nbsp;&nbsp;Doc</th>
								<th></th>
								
							</tr>
						</thead>
						<tbody>
						<g:each  in="${pratiche}" var="pratica">
						<g:if test="${pratica?.anomaliaBancaria}" >
						<g:set var="intervista" value="${ Interview.findById(pratica?.anomaliaBancaria?.interviewId)}"></g:set>
						<g:set var="anom_sovr_link" value="${createLink(controller:'pratica',action:'anomaliabancaria',id:pratica.identifier)}"></g:set>
						<g:set var="anom_sovr_LABEL" value="ANOMALIA"></g:set>
						</g:if>
						<g:else>
						<g:set var="intervista" value="${ Interview.findById(pratica?.sovraindebitamento?.interviewId)}"></g:set>
						</g:else>
							<tr style="font-size: 13px;">
<%--							ATTENZIONE!!! Manca la gestione del sovraindebitamento--%>
								<g:if test="${intervista?.customer?.personaGiuridica?.pgCf || 
										intervista?.customer?.personaGiuridica?.pgPiva && 
											intervista?.customer?.personaGiuridica?.pgName}">
									<td>${(intervista?.customer?.personaGiuridica?.pgName) ? (intervista?.customer?.personaGiuridica?.pgName).toUpperCase() : (intervista?.customer?.personaGiuridica?.pgName)}</td>
								</g:if><g:else>	
									<td>${(intervista?.customer?.surname) ? (intervista?.customer?.surname).toUpperCase() : (intervista?.customer?.surname)}&nbsp;&nbsp;${(intervista?.customer?.name) ? (intervista?.customer?.name).toUpperCase() : (intervista?.customer?.name)}</td>
								</g:else>
								<td style="font-size: 12;"><g:formatDate format="dd-MM-yy" date="${pratica.dateCreated}"/></td>
								<td>${pratica.user.surname}</td>
								<td style="font-size: 11;"><a href="${createLink(controller:'interview',action:'edit',id:intervista.id)}" ><exdutility:number_interview value="${intervista.id}"/></a></td>
								<td style="font-size: 11;"><a href="${anom_sovr_link}" >${anom_sovr_LABEL}</a></td>
								
<%--							ANOMALIA BANCARIA--%>
								<g:if test="${pratica?.anomaliaBancaria}" >
									<sec:ifAnyGranted roles="ROLE_ADMIN,ROLE_AMM,ROLE_BCKOFF">	
										<td style="font-size: 11;">
											---										
										</td>
										<td style="font-size: 11;">
											<a href="${createLink(controller:'perito',action:'show',id:pratica?.anomaliaBancaria?.perito?.id,params:[lp:'true'])}" >${(pratica?.anomaliaBancaria?.perito?.surname) ? (pratica?.anomaliaBancaria?.perito?.surname).toUpperCase() : (pratica?.anomaliaBancaria?.perito?.surname)}</a>										
										</td>
									</sec:ifAnyGranted>
									<td style="font-size: 10;">
										<g:if test="${pratica?.anomaliaBancaria?.refName}">
											<a href="javascript:void(0);" rel="popover" 
												data-placement="top"
												data-content="${pratica?.anomaliaBancaria?.refName}"
												aria-describedby="anomalia bancaria">
												<i class="fa fa-lg fa-info"></i>
											</a>
										</g:if>
										<exdutility:number_interview value="${pratica.identifier}"/>
									</td>								
								</g:if>
<%--							SOVRAINDEBITAMENTO--%>
								<g:elseif test="${pratica?.sovraindebitamento}" >	
								</g:elseif>
								
								<td align="center" style="font-size: 12;">
									<span>
										<a href="#" onclick="${createLink(action:'edit',id:pratica.id)}"><i class="fa fa-lg fa-sort-amount-asc"></i></a> 
									</span>&nbsp;&nbsp;&nbsp;
								<g:if test="${pratica?.anomaliaBancaria}" >
									<span><a href="${anom_sovr_link}" ><i class="fa fa-lg fa-paperclip"></i></a> </span></td>
								</g:if>
<%--							SOVRAINDEBITAMENTO--%>
								<g:elseif test="${pratica?.sovraindebitamento}" >	
									<span><a href="#" onclick="${createLink(action:'pages',id:pratica.id)}"><i class="fa fa-lg fa-paperclip"></i></a> </span></td>
								</g:elseif>
<%--					ATTENZIONE!		Manca edit perche ancora si deve gestire la pratica --%>
<%--							e la cancellazione della pratica e corrispettiva funzione se è un sovraddebitamento--%>
								<td align="center" style="font-size: 12;"><exdutility:btn_manage1 cancel-function="cancelPratica('${pratica?.identifier}')"/></td>
							</tr>	
						</g:each>
						</tbody>
					</table>
				</div>
				<!-- end widget content -->
			</div>
			<!-- end widget div -->
		</div>				
	</div>
</div>
</div>
<script src="${resource(dir: 'site/js/plugin/datatables', file: 'jquery.dataTables.min.js')}"></script>
<script src="${resource(dir: 'site/js/plugin/datatables', file: 'dataTables.colVis.min.js')}"></script>			
<script src="${resource(dir: 'site/js/plugin/datatables', file: 'dataTables.tableTools.min.js')}"></script>
<script src="${resource(dir: 'site/js/plugin/datatables', file: 'dataTables.bootstrap.min.js')}"></script>
<script src="${resource(dir: 'site/js/plugin/datatable-responsive', file: 'datatables.responsive.min.js')}"></script>

<script type="text/javascript">
		$(document).ready(function() {
			pageSetUp();
			buildTable();
		});

		function cancelPratica(identifier){
				$.SmartMessageBox({
					title : "<div class='row'><div class='col-md-2'><i class='fa '></i></div><div class='col-md-10'>Stai per eliminare una pratica dalla piattaforma!</div>",
					content : "<div class='col-md-2'></div><div class='col-md-10'> Sei sicuro di volerlo fare?<BR/><BR/></div></div>",
					buttons:"[Si],[No]",
					sound:false
				}, function(ButtonPressed, Value) {
					if (ButtonPressed === "No") {
						
					}
					if (ButtonPressed === "Si") {
						${remoteFunction(asynchronous: true,
			 					action:'deleteABandPratica',
								controller:'interview',
								params:'\'codPratica=\'+identifier',
								onSuccess:'showCancelResponse(data)'
								)} 
					}
					});
			}
		function showCancelResponse(data){
			$.smallBox({
				title : data.message,
				color : "#3F8DBF",
				sound:false,
				timeout: 3000
			});
			setTimeout(function(){ location.reload();}, 2000);
			
			}
			

		function buildTable(){
			/* BASIC ;*/
			var responsiveHelper_dt_basic = undefined;
			var responsiveHelper_datatable_fixed_column = undefined;
			var responsiveHelper_datatable_col_reorder = undefined;
			var responsiveHelper_datatable_tabletools = undefined;
			
			var breakpointDefinition = {
				tablet : 1024,
				phone : 480
			};

			$('#dt_basic').dataTable({
				"sDom": "<'dt-toolbar'<'col-xs-12 col-sm-6'f><'col-sm-6 col-xs-12 hidden-xs'l>r>"+
					"t"+
					"<'dt-toolbar-footer'<'col-sm-6 col-xs-12 hidden-xs'i><'col-xs-12 col-sm-6'p>>",
				"autoWidth" : true,
				"preDrawCallback" : function() {
					// Initialize the responsive datatables helper once.
					if (!responsiveHelper_dt_basic) {
						responsiveHelper_dt_basic = new ResponsiveDatatablesHelper($('#dt_basic'), breakpointDefinition);
					}
				},
				"rowCallback" : function(nRow) {
					responsiveHelper_dt_basic.createExpandIcon(nRow);
				},
				"drawCallback" : function(oSettings) {
					responsiveHelper_dt_basic.respond();
				}
			});

		/* END BASIC */
		
		/* COLUMN FILTER  */
	    var otable = $('#datatable_fixed_column').DataTable({
	    	//"bFilter": false,
	    	//"bInfo": false,
	    	//"bLengthChange": false
	    	//"bAutoWidth": false,
	    	//"bPaginate": false,
	    	//"bStateSave": true // saves sort state using localStorage
			"sDom": "<'dt-toolbar'<'col-xs-12 col-sm-6 hidden-xs'f><'col-sm-6 col-xs-12 hidden-xs'<'toolbar'>>r>"+
					"t"+
					"<'dt-toolbar-footer'<'col-sm-6 col-xs-12 hidden-xs'i><'col-xs-12 col-sm-6'p>>",
			"autoWidth" : true,
			"preDrawCallback" : function() {
				// Initialize the responsive datatables helper once.
				if (!responsiveHelper_datatable_fixed_column) {
					responsiveHelper_datatable_fixed_column = new ResponsiveDatatablesHelper($('#datatable_fixed_column'), breakpointDefinition);
				}
			},
			"rowCallback" : function(nRow) {
				responsiveHelper_datatable_fixed_column.createExpandIcon(nRow);
			},
			"drawCallback" : function(oSettings) {
				responsiveHelper_datatable_fixed_column.respond();
			}		
		
	    });
	    
	    // custom toolbar
	    $("div.toolbar").html('<div class="text-right"><img src="img/logo.png" alt="SmartAdmin" style="width: 111px; margin-top: 3px; margin-right: 10px;"></div>');
	    	   
	    // Apply the filter
	    $("#datatable_fixed_column thead th input[type=text]").on( 'keyup change', function () {
	    	
	        otable
	            .column( $(this).parent().index()+':visible' )
	            .search( this.value )
	            .draw();
	            
	    } );
	    /* END COLUMN FILTER */   

		/* COLUMN SHOW - HIDE */
		$('#datatable_col_reorder').dataTable({
			"sDom": "<'dt-toolbar'<'col-xs-12 col-sm-6'f><'col-sm-6 col-xs-6 hidden-xs'C>r>"+
					"t"+
					"<'dt-toolbar-footer'<'col-sm-6 col-xs-12 hidden-xs'i><'col-sm-6 col-xs-12'p>>",
			"autoWidth" : true,
			"preDrawCallback" : function() {
				// Initialize the responsive datatables helper once.
				if (!responsiveHelper_datatable_col_reorder) {
					responsiveHelper_datatable_col_reorder = new ResponsiveDatatablesHelper($('#datatable_col_reorder'), breakpointDefinition);
				}
			},
			"rowCallback" : function(nRow) {
				responsiveHelper_datatable_col_reorder.createExpandIcon(nRow);
			},
			"drawCallback" : function(oSettings) {
				responsiveHelper_datatable_col_reorder.respond();
			}			
		});
		
		/* END COLUMN SHOW - HIDE */

		/* TABLETOOLS */
		$('#datatable_tabletools').dataTable({
			
			// Tabletools options: 
			//   https://datatables.net/extensions/tabletools/button_options
			"sDom": "<'dt-toolbar'<'col-xs-12 col-sm-6'f><'col-sm-6 col-xs-6 hidden-xs'T>r>"+
					"t"+
					"<'dt-toolbar-footer'<'col-sm-6 col-xs-12 hidden-xs'i><'col-sm-6 col-xs-12'p>>",
	        "oTableTools": {
	        	 "aButtons": [
	             "copy",
	             "csv",
	             "xls",
	                {
	                    "sExtends": "pdf",
	                    "sTitle": "SmartAdmin_PDF",
	                    "sPdfMessage": "SmartAdmin PDF Export",
	                    "sPdfSize": "letter"
	                },
	             	{
	                	"sExtends": "print",
	                	"sMessage": "Generated by SmartAdmin <i>(press Esc to close)</i>"
	            	}
	             ],
	            "sSwfPath": "js/plugin/datatables/swf/copy_csv_xls_pdf.swf"
	        },
			"autoWidth" : true,
			"preDrawCallback" : function() {
				// Initialize the responsive datatables helper once.
				if (!responsiveHelper_datatable_tabletools) {
					responsiveHelper_datatable_tabletools = new ResponsiveDatatablesHelper($('#datatable_tabletools'), breakpointDefinition);
				}
			},
			"rowCallback" : function(nRow) {
				responsiveHelper_datatable_tabletools.createExpandIcon(nRow);
			},
			"drawCallback" : function(oSettings) {
				responsiveHelper_datatable_tabletools.respond();
			}
		});
		
			}
</script>			
</body>

</HTML>			

